const Koa = require("koa")
const Static = require("koa-static")
const Path = require("path")
const http = require("http")
const YBError = require("./lib/error/dispose")
const YBMiddleware = require("@/lib/YBMiddleware")
const cors = require('koa2-cors');

/**
 * 运行MongoDB
 */
require("@mongodb")

/**
 * 创建App
 */
const app = new Koa()
app.use(cors());
/**
 * 日志
 */
require('./logs')(app)

/**
 * 错误处理
 */
app.use(YBError);

/**
 * 自定义中间件
 */
app.use(YBMiddleware)

/**
 * 静态文件
 */
app.use(Static(Path.join(__dirname, 'static')))
app.use(Static(Path.join(__dirname, 'view')))

/**
 * 路由配置
 */
const router = require('./router/index')
app
  .use(router.routes(), router.allowedMethods())

console.log('prod = ', process.env.SERVER_PORT)
http.createServer(app.callback()).listen(process.env.SERVER_PORT);


